package com.armed.ejb.sessions;

import com.armed.ejb.entities.Telefonos;
import com.armed.ejb.transference.Telefono;
import com.armed.ejb.transference.helpers.DataReverseTransferHelper;
import com.armed.ejb.transference.helpers.DataTransferHelper;
import com.armed.excepciones.teldir.TelefonoRepetidoException;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Class TelefonosFacade
 *
 *
 * @author init() software
 * @version 08/02/2008 
 */
@Stateless
public class TelefonosFacade implements TelefonosFacadeRemote 
{
    @PersistenceContext
    private EntityManager em;
    /** Constructor of TelefonosFacade */
    public TelefonosFacade()
    {
    }

    public void create(Telefono telefonos)
    {
        Telefonos tels = DataReverseTransferHelper.revertPhone(telefonos);
        em.persist(tels);
    }

    public void edit(Telefono telefonos)
    {
        em.merge(DataReverseTransferHelper.revertPhone(telefonos));
    }

    public void remove(Telefono telefonos)
    {
        em.remove(em.merge(DataReverseTransferHelper.revertPhone(telefonos)));
    }

    public Telefono find(Object id)
    {
        return DataTransferHelper.copyPhone(em.find(com.armed.ejb.entities.Telefonos.class, id));
    }

    public List<Telefono> findAll()
    {
        return DataTransferHelper.copyPhonesToList(em.createQuery("select object(o) from Telefonos as o").getResultList());
    }
}
